#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
    int solve(int left,int right,vector<int>& nums)
    {
        vector<int> f(right+1),g(right+1);
        f[left]=nums[left];
        for(int i=left+1;i<=right;i++)
        {
            f[i]=g[i-1]+nums[i];
            g[i]=max(f[i-1],g[i-1]);
        }
        return g[right]>f[right]?g[right]:f[right];
    }
    int rob(vector<int>& nums) {
        int n=nums.size();
        if(n==0) return 0;
        if(n==1) return nums[0];
        int ret=max(solve(0,n-2,nums),solve(1,n-1,nums));
        return ret;
    }
};